package com.b2c.controller;

import com.b2c.annotation.ApiLimit;
import com.b2c.pojo.vo.CodeEmailVo;
import com.b2c.pojo.vo.CodePhoneVO;
import com.b2c.pojo.vo.EmailVo;
import com.b2c.pojo.vo.PhoneVo;
import result.Result;
import com.b2c.service.AdminUserService;
import freemarker.template.TemplateException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.mail.MessagingException;
import java.io.IOException;

@RestController
@RequestMapping("/admin")
@Slf4j
public class AdminLoginController {
    @Autowired
    AdminUserService adminUserService;

    /**
     * 手机号登录
     *
     * @param codePhoneVO
     * @return
     */
    @GetMapping("/login/phone")
    public Result adminLoginPhone(CodePhoneVO codePhoneVO) {
        return adminUserService.adminLoginPhone(codePhoneVO);
    }

    /**
     * 邮箱登录
     *
     * @param codeEmailVo
     * @return
     */
    @GetMapping("/login/email")
    public Result adminLoginEmail(CodeEmailVo codeEmailVo) {
        return adminUserService.adminLoginEmail(codeEmailVo);
    }

    /**
     * 账号密码登录
     *
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/login")
    public Result adminLoginSecret(String username, String password) {
        return adminUserService.adminLoginSecret(username, password);
    }

    /**
     * 修改密码,登录后才能修改
     *
     * @param password
     * @return
     */
    @PutMapping("/update/secret")
    public Result updateSecret(String password) {
        return adminUserService.updateSecret(password);
    }

    /**
     * 绑定手机号
     *
     * @param codePhoneVO
     * @return
     */
    @PutMapping("/bind/phone")
    public Result bindPhone(CodePhoneVO codePhoneVO) {
        return adminUserService.bindPhone(codePhoneVO);
    }

    /**
     * 绑定邮箱
     *
     * @param codeEmailVo
     * @return
     */
    @PutMapping("/bind/email")
    public Result bindEmail(CodeEmailVo codeEmailVo) {
        return adminUserService.bindEmail(codeEmailVo);
    }

    /**
     * 设置账号密码
     * 每个用户可以设置用户名密码，使用密码登录
     *
     * @param password
     * @return
     */
    @PutMapping("/setup/secret")
    public Result setupSecret(String password) {
        return adminUserService.setupSecret(password);
    }


    /**
     * 通过手机号注册
     *
     * @param codePhoneVO
     * @return
     */
    @PostMapping("/register/phone")
    public Result registerByPhone(CodePhoneVO codePhoneVO) {
        return adminUserService.registerByPhone(codePhoneVO);
    }

    /**
     * 邮箱注册
     *
     * @param codeEmailVo
     * @return
     */
    @PostMapping("/register/email")
    public Result registerByEmail(CodeEmailVo codeEmailVo) {
        return adminUserService.registerByEmail(codeEmailVo);
    }

    /***
     * 登出账号
     * @return
     */
    @GetMapping("logout")
    public Result logout() {
        return adminUserService.logout();
    }

}
